import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_axrjc/datasource/network/bean/EventBean.dart';
import 'package:flutter_axrjc/main.dart';
import 'package:get/get.dart';

import 'state.dart';

class CheckManageLogic extends GetxController
    with GetSingleTickerProviderStateMixin {
  final CheckManageState state = CheckManageState();
  late TabController tabController;
  var pageController = PageController();
  StreamSubscription<EventBean>? listener;
  @override
  void onInit() {
    super.onInit();
    tabController = TabController(length: 2, vsync: this);
    listener = eventBus.on<EventBean>().listen((event) {
      if (event.type == EventType.changeManagePage) {
        changePageTo(event.data as int);
      }
    });
  }

  void changePageTo(int i) {
    pageController.animateToPage(i,
        duration: const Duration(milliseconds: 200), curve: Curves.linear);
  }

  @override
  void onClose() {
    super.onClose();
    listener?.cancel();
  }
}
